package com.chagee.store.operation.server.config;

import com.chagee.store.operation.server.model.info.MessageInfo;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Objects;

/**
 * @Author : yzq
 * @Date : 2024/7/2
 */

@RefreshScope
@Data
@Configuration
@ConfigurationProperties(prefix = "lark.message")
public class LarkMessageConfig {

	private List<MessageInfo> infos;

	public MessageInfo getByType(String type) {
		MessageInfo messageInfo = new MessageInfo();
		for (MessageInfo info : infos) {
			if (Objects.equals(type, info.getType())) {
				BeanUtils.copyProperties(info,messageInfo);
				return messageInfo;
			}
		}
		return null;
	}

}
